﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;

namespace SizeboxUI
{
	// Token: 0x020003B6 RID: 950
	public class SettingsView : MonoBehaviour
	{
		// Token: 0x060019B0 RID: 6576 RVA: 0x000A0C20 File Offset: 0x0009EE20
		private void Awake()
		{
			this.gridGroup = base.GetComponentInChildren<GridLayoutGroup>();
			this.toggle = Resources.Load<Toggle>("UI/Pause/Toggle");
			this.toggleSlider = Resources.Load<GameObject>("UI/Pause/ToggleSlider");
			this.slider = Resources.Load<GameObject>("UI/Pause/Slider");
			this.readOnly = Resources.Load<GameObject>("UI/Pause/ReadOnly");
			this.numberedSlider = Resources.Load<GameObject>("UI/Pause/NumberedSlider");
			this.numberedIntSlider = Resources.Load<GameObject>("UI/Pause/NumberedIntSlider");
			this.dropdown = Resources.Load<GameObject>("UI/Pause/Dropdown");
			this.input = Resources.Load<GameObject>("UI/Pause/Input");
			this.inputSlider = Resources.Load<GameObject>("UI/Pause/InputSlider");
			this.header = Resources.Load<GameObject>("UI/Pause/Header");
			this.button = Resources.Load<GameObject>("UI/Button/Action Button");
			this.keyBind = Resources.Load<GameObject>("UI/Pause/KeyBind");
			base.GetComponentInChildren<Button>().onClick.AddListener(delegate()
			{
				this.ClosePanel();
			});
		}

		// Token: 0x060019B1 RID: 6577 RVA: 0x00069260 File Offset: 0x00067460
		protected void ClosePanel()
		{
			base.gameObject.SetActive(false);
		}

		// Token: 0x060019B2 RID: 6578 RVA: 0x000A0D18 File Offset: 0x0009EF18
		protected Button AddKeyBind(string text)
		{
			GameObject newKeyBind = UnityEngine.Object.Instantiate<GameObject>(this.keyBind);
			newKeyBind.GetComponentInChildren<Text>().text = text;
			newKeyBind.transform.SetParent(this.gridGroup.transform, false);
			Button btn = newKeyBind.GetComponentInChildren<Button>();
			btn.onClick.AddListener(delegate()
			{
				if (newKeyBind.GetComponentInChildren<KeyBindInput>() == null)
				{
					newKeyBind.AddComponent<KeyBindInput>();
					newKeyBind.GetComponent<KeyBindInput>().oldKeyName = btn.GetComponentInChildren<Text>().text;
					btn.GetComponentInChildren<Text>().text = "Awaiting input...";
				}
			});
			return btn;
		}

		// Token: 0x060019B3 RID: 6579 RVA: 0x000A0D9C File Offset: 0x0009EF9C
		public void SetInputSliderInput(SettingsView.InputSlider i, float f, string style = "####")
		{
			this.noset = true;
			i.input.text = f.ToString(style);
			this.noset = false;
		}

		// Token: 0x060019B4 RID: 6580 RVA: 0x000A0DC0 File Offset: 0x0009EFC0
		public void SetInputSliderInput(SettingsView.InputSlider i, int f)
		{
			this.noset = true;
			i.input.text = f.ToString();
			this.noset = false;
		}

		// Token: 0x060019B5 RID: 6581 RVA: 0x000A0DEC File Offset: 0x0009EFEC
		public void InputSanity(SettingsView.InputSlider i, string s)
		{
			if (this.noset)
			{
				return;
			}
			if (string.IsNullOrEmpty(s))
			{
				return;
			}
			bool flag = false;
			foreach (char c in s)
			{
				if (this.ValidateDigit(c) != '\0')
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				return;
			}
			float num = float.Parse(s, CultureInfo.InvariantCulture.NumberFormat);
			if (num == i.slider.value)
			{
				return;
			}
			if (num < i.slider.minValue)
			{
				num = i.slider.minValue;
			}
			else if (num > i.slider.maxValue)
			{
				num = i.slider.maxValue;
			}
			i.slider.value = num;
		}

		// Token: 0x060019B6 RID: 6582 RVA: 0x000A0EC9 File Offset: 0x0009F0C9
		public char ValidateNumber(char c)
		{
			if (!char.IsDigit(c) && c != '.')
			{
				c = '\0';
			}
			return c;
		}

		// Token: 0x060019B7 RID: 6583 RVA: 0x000A0EE2 File Offset: 0x0009F0E2
		public char ValidateDigit(char c)
		{
			if (!char.IsDigit(c))
			{
				c = '\0';
			}
			return c;
		}

		// Token: 0x060019B8 RID: 6584 RVA: 0x000A0EF4 File Offset: 0x0009F0F4
		protected Button AddButton(string text)
		{
			Button component = UnityEngine.Object.Instantiate<GameObject>(this.button).GetComponent<Button>();
			component.GetComponentInChildren<Text>().text = text;
			component.transform.SetParent(this.gridGroup.transform, false);
			return component;
		}

		// Token: 0x060019B9 RID: 6585 RVA: 0x000A0F38 File Offset: 0x0009F138
		protected SettingsView.ToggleSlider AddToggleSlider(string text, float min, float max)
		{
			SettingsView.ToggleSlider result = default(SettingsView.ToggleSlider);
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.toggleSlider);
			gameObject.GetComponentInChildren<Text>().text = text;
			gameObject.transform.SetParent(this.gridGroup.transform, false);
			result.toggle = gameObject.GetComponent<Toggle>();
			result.slider = gameObject.GetComponentInChildren<Slider>();
			result.slider.minValue = min;
			result.slider.maxValue = max;
			return result;
		}

		// Token: 0x060019BA RID: 6586 RVA: 0x000A0FB4 File Offset: 0x0009F1B4
		protected Toggle AddToggle(string text)
		{
			Toggle toggle = UnityEngine.Object.Instantiate<Toggle>(this.toggle);
			toggle.GetComponentInChildren<Text>().text = text;
			toggle.transform.SetParent(this.gridGroup.transform, false);
			return toggle;
		}

		// Token: 0x060019BB RID: 6587 RVA: 0x000A0FF4 File Offset: 0x0009F1F4
		protected InputField AddInput(string text, string placeHolderText)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.input);
			gameObject.GetComponentsInChildren<Text>()[0].text = text;
			gameObject.GetComponentsInChildren<Text>()[1].text = placeHolderText;
			gameObject.transform.SetParent(this.gridGroup.transform, false);
			return gameObject.GetComponentInChildren<InputField>();
		}

		// Token: 0x060019BC RID: 6588 RVA: 0x000A1048 File Offset: 0x0009F248
		protected SettingsView.InputSlider AddInputSlider(string text, float min, float max)
		{
			SettingsView.InputSlider newInputSlider = default(SettingsView.InputSlider);
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.inputSlider);
			gameObject.GetComponentInChildren<Text>().text = text;
			gameObject.transform.SetParent(this.gridGroup.transform, false);
			newInputSlider.input = gameObject.GetComponentInChildren<InputField>();
			newInputSlider.slider = gameObject.GetComponentInChildren<Slider>();
			newInputSlider.slider.minValue = min;
			newInputSlider.slider.maxValue = max;
			newInputSlider.input.onEndEdit.AddListener(delegate(string x)
			{
				this.InputSanity(newInputSlider, x);
			});
			return newInputSlider;
		}

		// Token: 0x060019BD RID: 6589 RVA: 0x000A110C File Offset: 0x0009F30C
		protected Slider AddSlider(string text, float min, float max)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.slider);
			gameObject.GetComponentInChildren<Text>().text = text;
			gameObject.transform.SetParent(this.gridGroup.transform, false);
			Slider componentInChildren = gameObject.GetComponentInChildren<Slider>();
			componentInChildren.minValue = min;
			componentInChildren.maxValue = max;
			return componentInChildren;
		}

		// Token: 0x060019BE RID: 6590 RVA: 0x000A1160 File Offset: 0x0009F360
		protected Text AddReadOnly(string title, string value)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.readOnly);
			gameObject.transform.SetParent(this.gridGroup.transform, false);
			Text[] componentsInChildren = gameObject.GetComponentsInChildren<Text>();
			Text result = null;
			foreach (Text text in componentsInChildren)
			{
				if (text.gameObject.name == "Property")
				{
					text.text = title;
				}
				else
				{
					text.text = value;
					result = text;
				}
			}
			return result;
		}

		// Token: 0x060019BF RID: 6591 RVA: 0x000A11EC File Offset: 0x0009F3EC
		protected Slider AddNumberedSlider(string text, float min, float max)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.numberedSlider);
			gameObject.GetComponentInChildren<Text>().text = text;
			gameObject.transform.SetParent(this.gridGroup.transform, false);
			Slider componentInChildren = gameObject.GetComponentInChildren<Slider>();
			componentInChildren.minValue = min;
			componentInChildren.maxValue = max;
			return componentInChildren;
		}

		// Token: 0x060019C0 RID: 6592 RVA: 0x000A1240 File Offset: 0x0009F440
		protected Slider AddNumberedIntSlider(string text, int min, int max)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.numberedIntSlider);
			gameObject.GetComponentInChildren<Text>().text = text;
			gameObject.transform.SetParent(this.gridGroup.transform, false);
			Slider componentInChildren = gameObject.GetComponentInChildren<Slider>();
			componentInChildren.minValue = (float)min;
			componentInChildren.maxValue = (float)max;
			return componentInChildren;
		}

		// Token: 0x060019C1 RID: 6593 RVA: 0x000A1294 File Offset: 0x0009F494
		protected Dropdown AddDropdown(string text, List<Dropdown.OptionData> options)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.dropdown);
			gameObject.GetComponentInChildren<Text>().text = text;
			gameObject.transform.SetParent(this.gridGroup.transform, false);
			Dropdown componentInChildren = gameObject.GetComponentInChildren<Dropdown>();
			componentInChildren.AddOptions(options);
			return componentInChildren;
		}

		// Token: 0x060019C2 RID: 6594 RVA: 0x000A12E0 File Offset: 0x0009F4E0
		protected Text AddHeader(string text)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.header);
			Text componentInChildren = gameObject.GetComponentInChildren<Text>();
			componentInChildren.text = text;
			componentInChildren.alignment = TextAnchor.MiddleCenter;
			gameObject.transform.SetParent(this.gridGroup.transform, false);
			return componentInChildren;
		}

		// Token: 0x060019C3 RID: 6595 RVA: 0x000A1328 File Offset: 0x0009F528
		public List<Dropdown.OptionData> CreateTextOptions(string[] strs, bool Capital = true)
		{
			List<Dropdown.OptionData> list = new List<Dropdown.OptionData>();
			foreach (string text in strs)
			{
				string text2 = text;
				if (Capital)
				{
					text2 = this.Capitalize(text2);
				}
				list.Add(new Dropdown.OptionData
				{
					text = text2
				});
			}
			return list;
		}

		// Token: 0x060019C4 RID: 6596 RVA: 0x000A1381 File Offset: 0x0009F581
		private string Capitalize(string str)
		{
			return Regex.Replace(str, "^[a-z]", (Match m) => m.Value.ToUpper());
		}

		// Token: 0x060019C5 RID: 6597 RVA: 0x000A13AB File Offset: 0x0009F5AB
		private void OnEnable()
		{
			if (this.initialized)
			{
				this.UpdateValues();
			}
		}

		// Token: 0x060019C6 RID: 6598 RVA: 0x00002973 File Offset: 0x00000B73
		protected virtual void UpdateValues()
		{
		}

		// Token: 0x04001BB4 RID: 7092
		protected bool initialized;

		// Token: 0x04001BB5 RID: 7093
		protected GridLayoutGroup gridGroup;

		// Token: 0x04001BB6 RID: 7094
		private Toggle toggle;

		// Token: 0x04001BB7 RID: 7095
		private GameObject slider;

		// Token: 0x04001BB8 RID: 7096
		private GameObject readOnly;

		// Token: 0x04001BB9 RID: 7097
		private GameObject numberedSlider;

		// Token: 0x04001BBA RID: 7098
		private GameObject numberedIntSlider;

		// Token: 0x04001BBB RID: 7099
		private GameObject dropdown;

		// Token: 0x04001BBC RID: 7100
		private GameObject header;

		// Token: 0x04001BBD RID: 7101
		private GameObject toggleSlider;

		// Token: 0x04001BBE RID: 7102
		private GameObject button;

		// Token: 0x04001BBF RID: 7103
		private GameObject input;

		// Token: 0x04001BC0 RID: 7104
		private GameObject inputSlider;

		// Token: 0x04001BC1 RID: 7105
		private GameObject keyBind;

		// Token: 0x04001BC2 RID: 7106
		public MainView main;

		// Token: 0x04001BC3 RID: 7107
		public bool noset;

		// Token: 0x020003B7 RID: 951
		public struct ToggleSlider
		{
			// Token: 0x04001BC5 RID: 7109
			public Toggle toggle;

			// Token: 0x04001BC6 RID: 7110
			public Slider slider;
		}

		// Token: 0x020003B8 RID: 952
		public struct InputSlider
		{
			// Token: 0x04001BC7 RID: 7111
			public InputField input;

			// Token: 0x04001BC8 RID: 7112
			public Slider slider;
		}
	}
}
